﻿<%@ WebHandler Language="C#" Class="WindowsPhonePostHandler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;

public class WindowsPhonePostHandler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        string ActionSwitch = "";
        ActionSwitch = context.Request.QueryString["Action"];
        //string type = context.Request.Form["type"];
        string strconn = LinkToDatabase.strConn;
        string strcmd = "";
        switch(ActionSwitch)
        {
            case "PostToMap":
                //==============目前是GET==============
                using (SqlConnection conn = new SqlConnection(strconn))
                {
                    strcmd = @"INSERT INTO [dbo].[google_map] ([dbo].[user_id],[product_id],[product_price],[geo_info],[geo_address_x],[geo_address_y],[date]) VALUES(@UId,@Product,@Price,@Info,@X,@Y,@date)";
                    using (SqlCommand cmd = new SqlCommand(strcmd, conn))
                    {
                        cmd.Parameters.AddWithValue("@UId", context.Request.QueryString["UserId"]);
                        cmd.Parameters.AddWithValue("@X", context.Request.QueryString["x"]);
                        cmd.Parameters.AddWithValue("@Y", context.Request.QueryString["y"]);
                        cmd.Parameters.AddWithValue("@Product", context.Request.QueryString["product"]);
                        cmd.Parameters.AddWithValue("@Price", context.Request.QueryString["price"]);
                        cmd.Parameters.AddWithValue("@Info", context.Request.QueryString["info"]);
                        cmd.Parameters.AddWithValue("@date", DateTime.Now);
                        conn.Open();
                        cmd.ExecuteNonQuery();
                        conn.Close();
                    }
                }
                //==============目前是GET==============
                break;
            default:
                return;
        }
        context.Response.ContentType = "text/html";
        context.Response.Write("<h1>ok</h1>");
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}